package com.kdtech.analyse.NewsPaper;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.analyse.AnalyseNews;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.RegexUtils;
import com.kdtech.utils.StringUtils;

/**
 * http://www.jzsbs.com/ 建筑时报
 * @author KK
 *
 */
public class JzsbsNewsPaperAnalyse implements AnalyseNews {

	
	public boolean isDetailPage(String url) {
		String[] regex = {
				"http://www.jzsbs.com/html/[0-9]*.htm",
				};
		return RegexUtils.matchAny(url, regex);
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		String html = urlMeta.getHtml();
		String url = urlMeta.getUrl();


		String title = null;
		String content = null;
		Long date = null;
		String dateStr = null;
		Document doc = Jsoup.parse(html);

		title =doc.select("span.title").text();
		dateStr = doc.select("table#table2").text();
		date=DateUtils.matchDate(dateStr);

		content =HtmlCleaner.getContentHtml(url,doc.select("span.article"));

			NewsMeta newspaper = new NewsMeta();
			newspaper.setUrl(url);
			newspaper.setTitle(StringUtils.trimSpace(title));
			newspaper.setContent(StringUtils.trimSpace(content));
			newspaper.setDate(date);
			return newspaper;


	}

	
	public boolean isTaskPage(String url) {
		return false;//无列表页面
	}

	
}
